package skipClass.java;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class ChooseExcuseActivity extends Activity
{
	private final static String TAG = "ClassSkippers";
	private Typeface font;
	private TextView ExcuseTV;
	private ListView ExcuseLV;
	private Button CancelButton;
	
	private ArrayList<String> AvailableExcuses;
	private ArrayAdapter<String> AvailableExcusesAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.choose_excuse);
		
		font = Typeface.createFromAsset(getAssets(), "font/GoodDog.otf");
		
		ExcuseTV = (TextView) findViewById(R.id.choose_excuse_tv);
		
		ExcuseTV.setTypeface(font);
		
		ExcuseLV = (ListView) findViewById(R.id.choose_excuse_lv);
		
		
		ExcuseLV.setOnItemClickListener(
				new OnItemClickListener() 
				{
					public void onItemClick(AdapterView<?> parent, View view,
							int position, long id) 
					{
						Intent intent = new Intent();
						intent.putExtra("ExcusePos", position);
						setResult(RESULT_OK, intent);
						finish();
					}
				}
			);
		
		CancelButton = (Button) findViewById(R.id.choose_excuse_cancel);
		
		CancelButton.setTypeface(font);
		
		Bundle extras = getIntent().getExtras();
		
		if (extras != null)
		{
			AvailableExcuses = extras.getStringArrayList("Excuses");
			
			Log.i(TAG, "Excuse array has " + AvailableExcuses.size() + " entries.");
			
			AvailableExcusesAdapter = new ArrayAdapter<String>(this, R.layout.choose_excuse_item, AvailableExcuses);
			
			ExcuseLV.setAdapter(AvailableExcusesAdapter);
			
			Log.i(TAG, "Excuse ListView adapter has " + ExcuseLV.getAdapter().getCount() + " entries.");
			
			AvailableExcusesAdapter.notifyDataSetChanged();
		}
	}
	
	public void onClick(View v)
	{
		if (v == CancelButton)
		{
			setResult(RESULT_CANCELED, null);
			finish();	
		}
	}
}
